package com.ssm.studen.controller;

import com.ssm.studen.model.Exampaper;
import com.ssm.studen.service.ExampaperService;
import com.ssm.studen.tool.ResponseMessage;
import com.ssm.studen.tool.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 试卷表：
 *      对外提供数据服务接口
 */
@Api(tags = "exampaper")
@RestController
public class ExampaperController {

    @Autowired
    private ExampaperService exampaperService;

    /*****************试卷表添加*******************/
    @ApiOperation("试卷表添加")
    @RequestMapping("/addExampaper")
    public int addExampaper(Exampaper exampaper){
        int IsAdd = 0;
        //传入数据判断
        //1.实体对象不能为空
        if(exampaper != null){
            //2.角色名称不能为空
            if(exampaper.getEpname() != null){
                //3.添加角色数据
                IsAdd = exampaperService.addExampaper(exampaper);
            }
        }
        return IsAdd;
    }


    /*****************试卷表修改更新*******************/
    @ApiOperation("试卷表修改更新")
    @RequestMapping("/updateExampaper")
    public ResponseMessage updateExampaper(Exampaper exampaper){
        //传入的参数不能为空
        if(exampaper != null){
            //参数当中主键不能为0
            if(exampaper.getEpnum() != 0){
                if(exampaperService.updateExampaper(exampaper) == 1){
                    if(exampaper.getEpname()!=null||exampaper.getEpclass()!=null||exampaper.getEptid()!=null){
                        exampaperService.updateExampaper(exampaper);
                    }
                    return Result.success("更新成功");
                }else{
                    return Result.error("更新失败");
                }
            }
        }
        return Result.error("传入参数不正确");
    }


    /*****************试卷表查询*******************/
    @ApiOperation("试卷表查询")
    @RequestMapping(value = "/selectExamper",method = RequestMethod.PUT)
    public ResponseMessage selectExampaper(int epnum){
        Map<String,List> map = new HashMap<>();
        List<Exampaper> listExampaper = exampaperService.selectExampaper(epnum);
        map.put("list",listExampaper);
        return Result.success("200",map);
    }
}




















